package logic

import (
	"common/model"
	"context"
	"errors"
	user "user_srv/proto"
)

func (u *UserServer) OrderList(ctx context.Context, req *user.OrderListRequest) (*user.OrderListResponse, error) {
	var order model.Order
	res, err := order.GetAllOrderByUserid(int(req.UserId))
	if err != nil {
		return nil, err
	}
	if len(res) == 0 {
		return nil, errors.New("您暂时没有订单")
	}
	var allOrder []*user.OrderInfo
	for _, v := range res {
		allOrder = append(allOrder, &user.OrderInfo{
			OrderId:       v.OrderId,
			MealProductId: int64(v.MealProductId),
			Num:           int64(v.Num),
			PayType:       int64(v.PayType),
			TotalPrice:    float32(v.TotalPrice),
			DiscountPrice: float32(v.DiscountPrice),
			ActualPrice:   float32(v.ActualPrice),
			Status:        int64(v.Status),
		})
	}
	return &user.OrderListResponse{
		AllOrder: allOrder,
	}, nil
}
